//
//  CommonDefine.h
//  Yuejia
//
//  Created by 陈家将 on 17/6/27.
//  Copyright (c) 2017年 chenjiajiang. All rights reserved.
//

#ifndef CommonDefine_h
#define CommonDefine_h

//弱引用宏
#define WS(weakSelf) __weak __typeof(&*self) weakSelf = self;
// 强引用弱指针宏
#define SWS(strongWeakSelf,weakSelf) __strong __typeof(&*weakSelf) strongWeakSelf = weakSelf;
// 弱指针宏
#define WVC(WeakVC,VCName) __weak __typeof(&*VCName) WeakVC = VCName;

// 主窗口
#define KEY_WINDOW       [[UIApplication sharedApplication] keyWindow]
// 日志输出宏
#ifdef DEBUG
#define DBLog(something, ...) NSLog((@"- 方法名: %s - %d行 - 输出信息: {\n\t" something @"\n}"), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#define DBLog(...)
#endif

// 同步主线程
#define dispatch_sync_main_safe(block)\
if ([NSThread isMainThread]) {\
block();\
} else {\
dispatch_sync(dispatch_get_main_queue(), block);\
}

// 异步主线程
#define dispatch_async_main_safe(block)\
if ([NSThread isMainThread]) {\
block();\
} else {\
dispatch_async(dispatch_get_main_queue(), block);\
}

// ----- 沙盒路径 -----
#define kCachesPath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]

//iOS系统版本
#define iOS11    [[[UIDevice currentDevice]systemVersion]floatValue] >= 11.0
#define iOS10    [[[UIDevice currentDevice]systemVersion]floatValue] >= 10.0
#define iOS9    [[[UIDevice currentDevice]systemVersion]floatValue] >= 9.0

// 通知名称
#define AlixpayPaySuccess                9000
#define AlixpayPaySuccessNotification   @"AlixpayPaySuccessNotification"
#define AlixpayPayFailNotification   @"AlixpayPayFailNotification"


//判断是否为NSNull对象
#define nullObject(o) [o isKindOfClass:[NSNull class]]

#define kAPP_VERSION         [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

// 公共
#define MainScreenBounds [[UIScreen mainScreen] bounds]
#define MainScreenSize [[UIScreen mainScreen] bounds].size
#define MainScreenWidth [[UIScreen mainScreen] bounds].size.width
#define MainScreenHeight [[UIScreen mainScreen] bounds].size.height

// 设备尺寸
#define NAVIGATION_HEIGHT 64.0
#define TABBAR_HEIGHT 49.0
#define NAVIGATION_ITEM_HEIGHT 29.0
#define SPACE 10.0
#define SEPARATORH 0.5
#define SCREEN_BOUNDS   [[UIScreen mainScreen] bounds]
#define SCREEN_SIZE    [[UIScreen mainScreen] bounds].size
#define SCREEN_WIDTH    [[UIScreen mainScreen] bounds].size.width
#define SCREEN_HEIGHT   [[UIScreen mainScreen] bounds].size.height
#define SCALE_HEIGHT(height)     (height * (SCREEN_HEIGHT / 667.0))
#define SCALE_WIDTH(width)       (width * (SCREEN_WIDTH / 375.0))
#define SCREEN_WIDTH_SCALE SCREEN_WIDTH / 375.0
#define SCREEN_MAX_LENGTH       (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH       (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))

#define StatusbarHeight 20.0f
#define NavigationItemHeight 44.0f
#define TableViewFooterViewHeight 12.0f

//设备类型
#pragma mark - 设备类型
#define IS_IPAD                 (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE               (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA               ([[UIScreen mainScreen] scale] >= 2.0)

#define IS_IPHONE_4_OR_LESS     (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE_5             (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0) // 5 与 SE
#define IS_IPHONE_6             (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0) // 6 与 7
#define IS_IPHONE_6P            (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0) // 6P 与 7P


// 常用布局尺寸
#define SCREEN_BOUNDS_WITHOUT_NAV CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATION_HEIGHT)
#define SCREEN_BOUNDS_WITHOUT_NAV_AND_TABBAR CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATION_HEIGHT - TABBAR_HEIGHT)
#define SCREEN_BOUNDS_WITHOUT_NAV_AND_TABBAR_TOP_MARGIN(margin) CGRectMake(0, margin, SCREEN_WIDTH, SCREEN_HEIGHT- margin)
#define SCREEN_BOUNDS_WITHOUT_NAV_AND_TOP_MARGIN(margin) CGRectMake(0, margin, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATION_HEIGHT - margin)
#define SCREEN_BOUNDS_WITHOUT_NAV_AND_CUSTOMHEIGHT(margin) CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATION_HEIGHT - margin)
#define SCREEN_BOUNDS_WITHOUT_NAV_AND_TABBAR_TOP_HEIGHT(margin) CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATION_HEIGHT - TABBAR_HEIGHT - margin)



//颜色定义 UIColorDefine
#define RGBCOLOR(r,g,b) [UIColor \
colorWithRed:(r)/255.0f \
green:(g)/255.0f \
blue:(b)/255.0f \
alpha:1]

#define RGBACOLOR(r,g,b,a) [UIColor \
colorWithRed:(r)/255.0f \
green:(g)/255.0f \
blue:(b)/255.0f \
alpha:(a)]

#define UIColorFromRGBA(rgbValue, alphaValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0x00FF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0x0000FF))/255.0 \
alpha:alphaValue]

#define UIColorFromRGB(rgbValue) UIColorFromRGBA(rgbValue, 1.0)

#define COLOR_GRAYISHBLUE [UIColor colorWithRed:128/255.0 green:130/255.0 blue:133/255.0 alpha:1]

// 常用颜色
#define COLOR_(color)           [UIColor colorWithHexString:color]
#define COLOR_VIEW_BACKGROUND   [UIColor colorWithHexString:@"f5f5f0"] // 全局背景色，淡灰
#define COLOR_NAV_BACKGROUND    [UIColor colorWithHexString:@"228B22"]
#define COLOR_BLACK             [UIColor colorWithHexString:@"000000"]
#define COLOR_GRAY              [UIColor colorWithHexString:@"C0C0C0"]
#define COLOR_WHITE             [UIColor colorWithHexString:@"FFFFFF"]
#define COLOR_RED               [UIColor colorWithHexString:@"FF0000"]
#define COLOR_CD_RED            [UIColor colorWithHexString:@"E3170D"] // 镉红
#define COLOR_ORANGE            [UIColor colorWithHexString:@"FF6100"]
#define COLOR_BROWN             [UIColor colorWithHexString:@"802A2A"] // 棕色
#define COLOR_BLUE              [UIColor colorWithHexString:@"0000FF"] // 蓝色
#define COLOR_DEEP_BLUE         [UIColor colorWithHexString:@"191970"] // 深蓝色
#define COLOR_TURQUOISE_BLUE    [UIColor colorWithHexString:@"00C78C"] // 土耳其玉色
#define COLOR_GREEN             [UIColor colorWithHexString:@"00FF00"]
#define COLOR_JADE_GREEN        [UIColor colorWithHexString:@"00C957"] // 翠绿色
#define COLOR_FOREST_GREEN      [UIColor colorWithHexString:@"228B22"] // 森林绿
#define COLOR_PURPLE            [UIColor colorWithHexString:@"A020F0"] // 紫色
#define COLOR_CLEAR             [UIColor clearColor] // 透明色

#define COLOR_BG COLOR_(@"f8f8f8") // 背景色，淡灰
#define COLOR_TEXT_GARY COLOR_(@"7f7f7f") // 灰色字体
#define COLOR_TEXT_COLOR COLOR_(@"3d4245") // 黑色字体
#define COLOR_TEXT_HIGHT COLOR_(@"ff7823") // 黄色高亮字体
#define COLOR_BORDER_BG COLOR_(@"e5e5e5") //淡灰色分割线
#define COLOR_SHADOW_BG COLOR_(@"f4f4f4") // 淡紫色
#define COLOR_LIGHT_BLUE COLOR_(@"043d9c") // 淡蓝色

// 常用字体
#define Font(size) [UIFont systemFontOfSize:size]
#define Font11 [UIFont systemFontOfSize:11.0]
#define Font12 [UIFont systemFontOfSize:12.0]
#define Font13 [UIFont systemFontOfSize:13.0]
#define Font14 [UIFont systemFontOfSize:14.0]
#define Font15 [UIFont systemFontOfSize:15.0]
#define Font16 [UIFont systemFontOfSize:16.0]
#define Font17 [UIFont systemFontOfSize:17.0]
#define Font18 [UIFont systemFontOfSize:18.0]

#define BUNDLE_NAME @"Resource"

#define isAppFirstStart @"isAppFirstStart"
#define isNotAppFirstInstall @"isNotAppFirstInstall"
#define userLoginStatusChange @"userLoginStatusChange"


#endif
